<?php
/**
 * @project kkzc
 * @date 2015-7-10
 * @author xialei <xialeistudio@gmail.com>
 */

namespace app\module\api\controllers;

use app\models\ApplyAccount;
use yii\data\ActiveDataProvider;
use yii\web\ForbiddenHttpException;

/**
 * 提现账户
 * @author xialei <xialeistudio@gmail.com>
 * Class ApplyAccountController
 * @package app\module\api\controllers
 */
class ApplyaccountController extends BaseController
{
    public $modelClass = 'app\models\ApplyAccount';

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['delete']);
        $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
        return $actions;
    }

    /**
     * @author xialei <xialeistudio@gmail.com>
     * @param string $action
     * @param ApplyAccount $model
     * @param array $params
     * @throws ForbiddenHttpException
     */
    public function checkAccess($action, $model = null, $params = [])
    {
        if (\Yii::$app->admin->isGuest && $model != null && $model->user_id != \Yii::$app->user->id && !\Yii::$app->request->isOptions) {
            throw new ForbiddenHttpException();
        }
    }

    public function prepareDataProvider()
    {
        return new ActiveDataProvider([
            'query' => ApplyAccount::find()->where(['user_id' => \Yii::$app->user->id])
        ]);
    }
}